﻿using UnityEngine;
using System.Collections;

public class UTimer:SingletonMono<UTimer>
{
	//public static void Add(float)
	private static Timer t;
	private static Timer timer
	{
		get
		{
			if(t == null)
			{
				t = new Timer();
			}
			return t;
		}
	}
	/// <summary>
	/// 添加一个延迟回调
	/// </summary>
	/// <param name="delay"></param>
	/// <param name="func"></param>
	/// <returns></returns>
	public static uint AddTimer(float delay,System.Action func)
	{
		instance.enabled = true;
		return timer.AddTimer(delay,func);
	}
	/// <summary>
	/// 添加一个重复的延迟回调
	/// </summary>
	/// <param name="delay"></param>
	/// <param name="repeatMax"></param>
	/// <param name="func"></param>
	/// <returns></returns>
	public static uint AddTimerRepeat(float delay,int repeatMax,System.Action func)
	{
		instance.enabled = true;
		return timer.AddSchedule(delay,repeatMax,func);
	}
	/// <summary>
	/// 添加一个重复永久的延迟回调
	/// </summary>
	/// <param name="delay"></param>
	/// <param name="func"></param>
	/// <returns></returns>
	public static uint AddTimerRepeat(float delay,System.Action func)
	{
		instance.enabled = true;
		return timer.AddSchedule(delay,int.MaxValue,func);
	}
	public static void Remove(uint id)
	{
		timer.RemoveTimer(id);
	}
	void Update()
	{
		if(!t.Update(Time.deltaTime))
		{
			enabled = false;
		}
	}
}
